package ArticleController

import (
    "github.com/gin-gonic/gin"
    "server/app"
    "server/entity"
    "server/service/ArticleService"
)

// 查询文章列表
func FindList(c *gin.Context) {
    filter := new(entity.ArticleFilter)
    app.MustShouldBindJSON(c, &filter)

    list, err := ArticleService.FindList(filter)
    app.Json(c, app.NewRest().Result(err).Data(list))
}

// 根据主键查询单个文章
func FindById(c *gin.Context) {
    var obj struct{ Id string `json:"id"` }
    app.MustShouldBindJSON(c, &obj)

    item, err := ArticleService.FindById(obj.Id)
    app.Json(c, app.NewRest().Result(err).Data(item))
}

// 查询文章分页列表
func FindPageList(c *gin.Context) {
    pageFilter := new(entity.ArticlePageFilter)
    app.MustShouldBindJSON(c, &pageFilter)

    list, err := ArticleService.FindPageList(pageFilter)
    app.Json(c, app.NewRest().Result(err).Data(list))
}

// 查询要闻文章列表
func FindYaoList(c *gin.Context) {
    var obj struct{ Count int `json:"count"` }
    app.MustShouldBindJSON(c, &obj)

    list := ArticleService.FindYaoList(obj.Count)
    app.Json(c, app.NewRest().Data(list))
}

// 查询幻灯片文章列表
func FindSlideList(c *gin.Context) {
    var obj struct{ Count int `json:"count"` }
    app.MustShouldBindJSON(c, &obj)

    list := ArticleService.FindSlideList(obj.Count)
    app.Json(c, app.NewRest().Data(list))
}